<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
</head>
<body>
  <div id='root'></div>
  <script>
    const Button = {
      name: 'el-button',
      template: `<button @click='onClick'>{{ label }}</button>`,
      props: {
        label: {
          default: '按钮'
        }
      },
      methods: {
        onClick() {
          this.$emit('click')
        }
      }
    }

    // 假设我们是写一个组件库
    const XUI = [
      Button,
      // ... 其它很多组件
    ]

    // plugins
    // { install(Vue, options) {} }
    XUI.install = (Vue, options) => {
      XUI.forEach(({name, ...component}) => {
        Vue.component(name, component);
      })
    }

    Vue.use(XUI);

    new Vue({
      el: document.querySelector('#root'),
      template:`
       <div>
        <h1>hello world!</h1>
        <el-button label='click me!' @click='handleClick'/>  
      </div>
      `,
      methods: {
        handleClick() {
          console.log('点击生效了~')
        }
      }
    })
  </script>
</body>
</html>